//
//  DemoNSCoding.m
//  ocdemo
//
//  Created by JIENING ZHANG on 2019/7/25.
//  Copyright © 2019 JIENING ZHANG. All rights reserved.
//

#import "DemoNSCoding.h"

@implementation DemoNSCoding

- (instancetype)init {
    self = [super init];
    if(self) {
        _cDate = [NSDate date];
    }
    
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    if(self.name) {
        [aCoder encodeObject:self.name forKey:@"name"];
    }
    if(self.cDate) {
        [aCoder encodeObject:self.cDate forKey:@"cDate"];
    }
    if(self.binData) {
        [aCoder encodeObject:self.binData forKey:@"binData"];
    }
    if(self.info) {
        [aCoder encodeObject:self.info forKey:@"info"];
    }
    if(self.children) {
        [aCoder encodeObject:self.children forKey:@"children"];
    }
}

- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
    self= [super init];
    if(self) {
        _name = [aDecoder decodeObjectForKey:@"name"];
        _cDate = [aDecoder decodeObjectForKey:@"cDate"];
        _binData = [aDecoder decodeObjectForKey:@"binData"];
        _info = [aDecoder decodeObjectForKey:@"info"];
        _children = [aDecoder decodeObjectForKey:@"children"];
    }
    return self;
}

- (NSString*)description {
    NSString *show = [NSString stringWithFormat:@" ( name:%@, cDate:%@, binData:%@, info:{%@}, children:[%@] ) ",
        self.name, self.cDate, self.binData, self.info, self.children];
    return show;
}

@end
